package com.dinnerwithfriends.client.authentication.facebook;

import com.dinnerwithfriends.client.LandingPage;
import com.dinnerwithfriends.client.authentication.facebook.sdk.FBCore;
import com.dinnerwithfriends.client.authentication.facebook.sdk.FBEvent;
import com.dinnerwithfriends.client.dinner.invite.InitializeDinner;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 
 * @Feature
 */
public class FacebookAuthentication {

	// public static String APPID = "158550007562379"; // localhost

	public static String APPID = "153206831435128";

	private FBCore fbCore = GWT.create(FBCore.class);
	private FBEvent fbEvent = GWT.create(FBEvent.class);

	private boolean status = true;
	private boolean xfbml = true;
	private boolean cookie = true;

	public FacebookAuthentication() {

		fbCore.init(APPID, status, cookie, xfbml);

		if (fbCore.getSession() == null) {

			new LandingPage();

		} else {

			new InitializeDinner(fbCore);
		}

		fbEvent.subscribe("auth.sessionChange",
				new AsyncCallback<JavaScriptObject>() {

					@Override
					public void onFailure(Throwable caught) {

					}

					@Override
					public void onSuccess(JavaScriptObject result) {

						new FacebookAuthentication();
					}
				});
	}
}
